package com.itheima.tanhua.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.itheima.tanhua.api.db.UserServiceApi;
import com.itheima.tanhua.mapper.UserMapper;
import com.itheima.tanhuan.pojo.db.Friend;
import com.itheima.tanhuan.pojo.db.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService//发布到注册中心
public class UserServiceApiImpl implements UserServiceApi {
    @Autowired
    private UserMapper userMapper;



    @Override
    public User findByPhone(String phone) {
        LambdaQueryWrapper<User> wrapper=new LambdaQueryWrapper<User>();
        wrapper.eq(User::getMobile,phone);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public Integer update(User user) {
        int i = userMapper.updateById(user);
        return i;
    }

    @Override
    public User findById(Long userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public User findByHuanxiId(String huanxinId) {
        LambdaQueryWrapper<User> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(User::getHxUser,huanxinId);
       return userMapper.selectOne(wrapper);
    }


}
